home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: using MALLOC() w/ 2-d arrays
- Date: Fri, 26 Jan 1996 17:34:16 +0200
- Organization: Carelcomp Forest
- Message-ID: <3108F478.1831@cmt.lpr.mail.carel.fi>
- References: <4e9nm2$nna@cville-srv.wam.umd.edu>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- jeffrey d squires wrote:
- >
- > I have a function that takes as one of its arguments:
- >
- > unsigned char image[MAX_Y][MAX_X}
- >
- > I have a number of images which is determined at run time,
- > therefore I can't declare the size of image_array[][MAX_Y][MAX_X].
- >
- > In other words, I want to be able to allocate space for as many
- > of these images as I need at run time. I've tried everything
- > (except the correct way).
- >
- > I think I need something of the form:
- >
- > unsigned char * image_array[MAX_Y][MAX_X];
- >
- > image_array = (unsigned char *) malloc(.....sizeof(unsigned char));
- >
- > I know that if I declare:
- > unsigned char image_array[10][MAX_Y][MAX_X];
- >
- > I can successfully send this to the function, but what
- > if I don't know that I'll need ten? Can anyone tell
- > me the proper solution? Thank you.
-
- You could try:
-
- typedef unsigned char ia_type[MAX_Y][MAX_X];
-
- ia_type *image_array;
-
- image_array = (ia_type*)calloc(numelems, sizeof(ia_type));
-
- image_array[0][1][2] = 'X';
- ...
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-